<template>
  <view>
    <!-- 地址 -->
    <navigator
      url="/pages/address/address?source=1"
      class="address-section"
    >
      <view class="order-content">
        <text class="yticon icon-shouhuodizhi" />
        <view class="cen">
          <text class="address">
            {{ addressData.addressName }}
          </text>
          <text>
            {{ addressData.area }}
          </text>
          <view class="top">
            <text class="moble">
              {{ addressData.name }} {{ addressData.mobile | formatMobile }}
            </text>
          </view>
          
        </view>
        <text class="yticon icon-you" />
      </view>

      <image
        class="a-bg"
        src=""
      />
    </navigator>

    <view class="goods-section">
      <!-- 商品列表 -->
      <view
        class="goods-box-single"
      >
        <!-- 商品图片 -->
        <image
          class="goods-img"
          :src="orderDetail.goodImg"
          mode="aspectFill"
        />
        <!-- 订单商品详情 -->
        <view class="right">
          <text class="title clamp">
            {{ orderDetail.goodName }}
          </text>
          <view class="good-detail-info">
            <text class="attr-box">
              配送模式：{{ orderDetail.deliveryModel | formatDeliveryModel }}
            </text>
            <text class="attr-box">
              配送时间：{{ orderDetail.deliveryStart }} 至 {{ orderDetail.deliveryEnd }}
            </text>
            <text class="attr-box">
              每日数量：{{ orderDetail.avgNumPreDay }}件
            </text>
            <text class="attr-box">
              总数量：  {{ orderDetail.totalNum }}件
            </text>
          </view>
        </view>
        <view class="price-box">
          ￥{{ orderDetail.goodPrice }}
        </view>
      </view>
    </view>

    <!-- 金额明细 -->
    <view class="yt-list">
      <view class="yt-list-cell b-b">
        <text class="cell-tit clamp">
          商品总计
        </text>
        <text class="cell-tip">
          ￥{{totalAmount}}
        </text>
      </view>
      <view class="yt-list-cell b-b">
        <text class="cell-tit clamp">
          优惠金额
        </text>
        <text class="cell-tip red">
          -￥{{couponAmount.toFixed(2)}}
        </text>
      </view>
      <view class="yt-list-cell b-b">
        <text class="cell-tit clamp">
          配送
        </text>
        <text class="cell-tip">
          ￥{{postAmount.toFixed(2)}}
        </text>
      </view>
    </view>
		
    <!-- 底部 -->
    <view class="footer">
      <view class="price-content">
        <text>实付款</text>
        <text class="price-tip">
          ￥
        </text>
        <text class="price">
          {{payAmount}}
        </text>
      </view>
      <text
        class="submit"
        @click="submit"
      >
        立即支付
      </text>
    </view>
    <wechat-pay
      ref="wechatPay"
    />
  </view>
</template>

<script>
import { mapState } from 'vuex'
import wechatPay from '@/components/wechatPay.vue'

export default {
  components: {
    wechatPay
  },
  data() {
    return {
      maskState: 0, // 优惠券面板显示状态
      desc: '', // 备注
      payType: 1, // 1微信 2支付宝
      couponList: [
        {
          title: '新用户专享优惠券',
          price: 5,
        },
        {
          title: '庆五一发一波优惠券',
          price: 10,
        },
        {
          title: '优惠券优惠券优惠券优惠券',
          price: 15,
        }
      ],
      addressData: {
        name: '',
        mobile: '18888888888',
        addressName: '',
        address: '',
        area: '',
        default: false,
      },
      totalAmount: 0,
      // 优惠金额
      couponAmount: 0.00,
      // 配送费
      postAmount: 0.00,
      // 订单信息
      orderDetail: {
        goodId: '',
        goodName: '',
        goodPrice: '',
        goodImg: '/static/temp/cate20.jpg',
        deliveryModel: '',
        avgNumPreDay: '',
        totalNum: '',
        deliveryStart: '',
        deliveryEnd: '',
      }
    }
  },
  computed: {
    ...mapState(['userInfo']),
    payAmount() {
      const payAmount = this.totalAmount - this.couponAmount - this.postAmount
      return payAmount.toFixed(2)
    }
  },
  onLoad(option) {
    // 订单编号
    this.orderNo = option.orderNo
    // 商品数据
    const orderDetail = JSON.parse(option.orderDetail)
    this.orderDetail = orderDetail
    this.totalAmount = orderDetail.orderSumPrice
    this.getAddressList()
  },
  methods: {
    // 获取收货地址
    async getAddressList() {
      const res = await this.$api.json('getAddressList', { openId: this.userInfo.openId })
      this.addressData = res.find(item => item.isDefault === 1)
    },
    // 提交订单
    async submit(){
      const orderNo = await this.$api.json('order', {
        deliveryAddress: this.addressData.address,
        deliveryProvince: '',
        deliveryCity: '',
        deliveryTown: '',
        receiverMobile: this.addressData.mobile,
        receiverName: this.addressData.name,
        deliveryModel: this.orderDetail.deliveryModel,
        deliveryStart: this.orderDetail.deliveryStart,
        deliveryEnd: this.orderDetail.deliveryEnd,
        avgNumPreDay: this.orderDetail.avgNumPreDay,
        totalNum: this.orderDetail.totalNum,
        goodId: this.orderDetail.goodId,
        totalAmount: this.totalAmount,
        couponAmount: this.couponAmount,
        postAmount: this.postAmount,
        payAmount: this.payAmount,
      })
      this.$refs.wechatPay.toggleMask()
      this.$refs.wechatPay.orderNo = orderNo
      // uni.redirectTo({
      //   url: '/pages/money/pay'
      // })
    },
    stopPrevent(){}
  }
}
</script>

<style lang="scss">
	page {
		background: $page-color-base;
		padding-bottom: 100rpx;
	}

	.address-section {
		padding: 30rpx 0;
		background: #fff;
		position: relative;

		.order-content {
			display: flex;
			align-items: center;
		}

		.icon-shouhuodizhi {
			flex-shrink: 0;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 90rpx;
			color: #888;
			font-size: 44rpx;
		}

		.cen {
			display: flex;
			flex-direction: column;
			flex: 1;
			font-size: 28rpx;
			color: $font-color-base;
		}

		.name {
			font-size: 34rpx;
			margin-right: 24rpx;
		}

		.address {
			margin-top: 16rpx;
			margin-right: 20rpx;
			color: $font-color-dark;
      font-size: $font-lg;
		}

		.icon-you {
			font-size: 32rpx;
			color: $font-color-light;
			margin-right: 30rpx;
		}

		.a-bg {
			position: absolute;
			left: 0;
			bottom: 0;
			display: block;
			width: 100%;
			height: 5rpx;
		}
	}

	.goods-section {
		margin-top: 16rpx;
		background: #fff;
		padding-bottom: 1px;

		.g-header {
			display: flex;
			align-items: center;
			height: 84rpx;
			padding: 0 30rpx;
			position: relative;
		}

		.logo {
			display: block;
			width: 50rpx;
			height: 50rpx;
			border-radius: 100px;
		}

		.name {
			font-size: 30rpx;
			color: $font-color-base;
			margin-left: 24rpx;
		}

		.g-item {
			display: flex;
			margin: 20rpx 30rpx;

			image {
				flex-shrink: 0;
				display: block;
				width: 140rpx;
				height: 140rpx;
				border-radius: 4rpx;
			}

			.right {
				flex: 1;
				padding-left: 24rpx;
				overflow: hidden;
			}

			.title {
				font-size: 30rpx;
				color: $font-color-dark;
			}

			.spec {
				font-size: 26rpx;
				color: $font-color-light;
			}

			.price-box {
				display: flex;
				align-items: center;
				font-size: 32rpx;
				color: $font-color-dark;
				padding-top: 10rpx;

				.price {
					margin-bottom: 4rpx;
				}
				.number{
					font-size: 26rpx;
					color: $font-color-base;
					margin-left: 20rpx;
				}
			}

			.step-box {
				position: relative;
			}
		}
	}
	.yt-list {
		margin-top: 16rpx;
		background: #fff;
	}

	.yt-list-cell {
		display: flex;
		align-items: center;
		padding: 10rpx 30rpx 10rpx 40rpx;
		line-height: 70rpx;
		position: relative;

		&.cell-hover {
			background: #fafafa;
		}

		&.b-b:after {
			left: 30rpx;
		}

		.cell-icon {
			height: 32rpx;
			width: 32rpx;
			font-size: 22rpx;
			color: #fff;
			text-align: center;
			line-height: 32rpx;
			background: #f85e52;
			border-radius: 4rpx;
			margin-right: 12rpx;

			&.hb {
				background: #ffaa0e;
			}

			&.lpk {
				background: #3ab54a;
			}

		}

		.cell-more {
			align-self: center;
			font-size: 24rpx;
			color: $font-color-light;
			margin-left: 8rpx;
			margin-right: -10rpx;
		}

		.cell-tit {
			flex: 1;
			font-size: 26rpx;
			color: $font-color-light;
			margin-right: 10rpx;
		}

		.cell-tip {
			font-size: 26rpx;
			color: $font-color-dark;

			&.disabled {
				color: $font-color-light;
			}

			&.active {
				color: $base-color;
			}
			&.red{
				color: $base-color;
			}
		}

		&.desc-cell {
			.cell-tit {
				max-width: 90rpx;
			}
		}

		.desc {
			flex: 1;
			font-size: $font-base;
			color: $font-color-dark;
		}
	}
	
	/* 支付列表 */
	.pay-list{
		padding-left: 40rpx;
		margin-top: 16rpx;
		background: #fff;
		.pay-item{
			display: flex;
			align-items: center;
			padding-right: 20rpx;
			line-height: 1;
			height: 110rpx;	
			position: relative;
		}
		.icon-weixinzhifu{
			width: 80rpx;
			font-size: 40rpx;
			color: #6BCC03;
		}
		.icon-alipay{
			width: 80rpx;
			font-size: 40rpx;
			color: #06B4FD;
		}
		.icon-xuanzhong2{
			display: flex;
			align-items: center;
			justify-content: center;
			width: 60rpx;
			height: 60rpx;
			font-size: 40rpx;
			color: $base-color;
		}
		.tit{
			font-size: 32rpx;
			color: $font-color-dark;
			flex: 1;
		}
	}
	
	.footer{
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 995;
		display: flex;
		align-items: center;
		width: 100%;
		height: 90rpx;
		justify-content: space-between;
		font-size: 30rpx;
		background-color: #fff;
		z-index: 998;
		color: $font-color-base;
		box-shadow: 0 -1px 5px rgba(0,0,0,.1);
		.price-content{
			padding-left: 30rpx;
		}
		.price-tip{
			color: $base-color;
			margin-left: 8rpx;
		}
		.price{
			font-size: 36rpx;
			color: $base-color;
		}
		.submit{
			display:flex;
			align-items:center;
			justify-content: center;
			width: 280rpx;
			height: 100%;
			color: #fff;
			font-size: 32rpx;
			background-color: $base-color;
		}
	}
	
	/* 优惠券面板 */
	.mask{
		display: flex;
		align-items: flex-end;
		position: fixed;
		left: 0;
		top: var(--window-top);
		bottom: 0;
		width: 100%;
		background: rgba(0,0,0,0);
		z-index: 9995;
		transition: .3s;
		
		.mask-content{
			width: 100%;
			min-height: 30vh;
			max-height: 70vh;
			background: #f3f3f3;
			transform: translateY(100%);
			transition: .3s;
			overflow-y:scroll;
		}
		&.none{
			display: none;
		}
		&.show{
			background: rgba(0,0,0,.4);
			
			.mask-content{
				transform: translateY(0);
			}
		}
	}

	/* 优惠券列表 */
	.coupon-item{
		display: flex;
		flex-direction: column;
		margin: 20rpx 24rpx;
		background: #fff;
		.con{
			display: flex;
			align-items: center;
			position: relative;
			height: 120rpx;
			padding: 0 30rpx;
			&:after{
				position: absolute;
				left: 0;
				bottom: 0;
				content: '';
				width: 100%;
				height: 0;
				border-bottom: 1px dashed #f3f3f3;
				transform: scaleY(50%);
			}
		}
		.left{
			display: flex;
			flex-direction: column;
			justify-content: center;
			flex: 1;
			overflow: hidden;
			height: 100rpx;
		}
		.title{
			font-size: 32rpx;
			color: $font-color-dark;
			margin-bottom: 10rpx;
		}
		.time{
			font-size: 24rpx;
			color: $font-color-light;
		}
		.right{
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			font-size: 26rpx;
			color: $font-color-base;
			height: 100rpx;
		}
		.price{
			font-size: 44rpx;
			color: $base-color;
			&:before{
				content: '￥';
				font-size: 34rpx;
			}
		}
		.tips{
			font-size: 24rpx;
			color: $font-color-light;
			line-height: 60rpx;
			padding-left: 30rpx;
		}
		.circle{
			position: absolute;
			left: -6rpx;
			bottom: -10rpx;
			z-index: 10;
			width: 20rpx;
			height: 20rpx;
			background: #f3f3f3;
			border-radius: 100px;
			&.r{
				left: auto;
				right: -6rpx;
			}
		}
  }
  .goods-box-single{
    display: flex;
    padding: 20rpx 0;
    align-items: center;
    position: relative;
    border-bottom: 1px solid #ccc;
    border-top: 1px solid #ccc;
    margin-bottom: 10rpx;
    .goods-img{
      margin-left: 20rpx;
      display: block;
      width: 140rpx;
      height: 140rpx;
    }
    .good-detail-info {
      display: flex;
      flex-direction: column;

    }
    .right{
      flex: 1;
      display: flex;
      flex-direction: column;
      padding: 0 30rpx 0 24rpx;
      overflow: hidden;
      .title{
        font-size: $font-base + 2rpx;
        color: $font-color-dark;
        margin-bottom: 10rpx;
      }
      .attr-box{
        font-size: $font-sm;
        color: $font-color-light;
        padding: 2rpx 0;
      }
    }
    .price-box{
      display: flex;
      justify-content: flex-end;
      align-items: baseline;
      position: absolute;
      top: 20rpx;
      right: 0;
      padding: 0 30rpx;
      font-size: $font-sm + 2rpx;
      color: $font-color-dark;
    }
  }

</style>
